package com.company.word.servlet;

import com.company.word.dao.IWordDAO;
import com.company.word.dao.WordDAOImpl;
import com.company.word.pojo.Word;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@WebServlet("/findAllcheck")
public class FindAllCheckServlet extends HttpServlet
{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		// HttpServletRequest req 
		// Tomcat自动创建的对象，会把用户的请求信息放入
		
//		HttpServletResponse resp
		// Tomcat自动创建的对象, 通过它给用户发信息
		
		// 1. 获取用户提交的参数

		IWordDAO dao = new WordDAOImpl();
		List<Word> list=new ArrayList<>();
		try {
			list =  dao.findAll();
			System.out.println(list.toArray());
			if(list!=null)
			{
				resp.setHeader("Content-Type","text/html;charset=utf-8");
				Iterator<Word> it = list.iterator();
				         while (it.hasNext()) {
				            Word str = (Word) it.next();
							 resp.getWriter().println(str);
				        }

			}
			else
			{
				resp.getWriter().print("find fail");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		

		
		
	}
	

}
